package com.zh.note.huawei.onehundred.矩阵元素的边界值;


import java.util.ArrayList;
import java.util.List;

/**
 * @Author: zhanghuan
 * @date: 2023/8/28 20:00
 * @description: create it
 */
public class Main {
    public static void main(String[] args) {
        // Scanner sc = new Scanner(System.in);
        // String input = sc.nextLine();
        String input = "[[1,2,3],[3,4,5]]";
        String substring = input.substring(1, input.length() - 1);
        List<List<Integer>> target = new ArrayList<>();
        List<Integer> temp = null;
        for (int i = 0; i < substring.length(); i++) {

            char ch = substring.charAt(i);
            if (ch == '[') {
                temp = new ArrayList<Integer>();
            }
            if (Character.isDigit(ch)) {
                temp.add(Integer.parseInt(String.valueOf(ch)));
            }
            if (ch == ']') {
                target.add(temp);
                temp = null;
            }

        }
        int[][] matrix = new int[target.size()][target.get(0).size()];
        int index = 0;
        for (List<Integer> list : target) {
            int[] ints = list.stream().mapToInt(Integer::intValue).toArray();
            matrix[index] = ints;
            index++;
        }
        int res = getMinMatrix(matrix);
        System.out.println(res);


    }

    private static int getMinMatrix(int[][] arr) {
        int row = arr.length;
        int col = arr[0].length;
        List<Integer> temp = new ArrayList<>();
        for (int j = 0; j < col; j++) {
            int res = arr[0][j];
            for (int i = 0; i < row; i++) {
                res = Math.max(res, arr[i][j]);

            }
            temp.add(res);
        }
        temp.sort(Integer::compareTo);
        return temp.get(0);

    }
}
